home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / ziodev2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-18  |  3.9 KB  |  132 lines

  1. /* Copyright (C) 1993, 1994, 1996 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* ziodev2.c */
  20. /* (Level 2) IODevice operators */
  21. #include "string_.h"
  22. #include "ghost.h"
  23. #include "gp.h"
  24. #include "errors.h"
  25. #include "oper.h"
  26. #include "stream.h"
  27. #include "gxiodev.h"
  28. #include "files.h"                /* for file_open_stream */
  29. #include "iparam.h"
  30. #include "iutil2.h"
  31. #include "store.h"
  32.  
  33. /* ------ %null% ------ */
  34.  
  35. /* This represents the null output file. */
  36. private iodev_proc_open_device(null_open);
  37. gx_io_device gs_iodev_null =
  38.   { "%null%", "FileSystem",
  39.      { iodev_no_init, null_open, iodev_no_open_file,
  40.        iodev_os_fopen, iodev_os_fclose,
  41.        iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
  42.        iodev_no_enumerate_files, NULL, NULL,
  43.        iodev_no_get_params, iodev_no_put_params
  44.      }
  45.   };
  46.  
  47. private int
  48. null_open(gx_io_device *iodev, const char *access, stream **ps,
  49.   gs_memory_t *mem)
  50. {    if ( !streq1(access, 'w') )
  51.         return_error(e_invalidfileaccess);
  52.     return file_open_stream(gp_null_file_name,
  53.                 strlen(gp_null_file_name),
  54.                 access, 256 /* arbitrary */, ps,
  55.                 iodev->procs.fopen);
  56. }
  57.  
  58. /* ------ %ram% ------ */
  59.  
  60. /* This is an IODevice with no interesting parameters for the moment. */
  61. gx_io_device gs_iodev_ram =
  62.   { "%ram%", "Special",
  63.      { iodev_no_init, iodev_no_open_device, iodev_no_open_file,
  64.        iodev_no_fopen, iodev_no_fclose,
  65.        iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
  66.        iodev_no_enumerate_files, NULL, NULL,
  67.        iodev_no_get_params, iodev_no_put_params
  68.      }
  69.   };
  70.  
  71. /* ------ Operators ------ */
  72.  
  73. /* <iodevice> .getdevparams <mark> <name> <value> ... */
  74. private int
  75. zgetdevparams(os_ptr op)
  76. {    gx_io_device *iodev;
  77.     stack_param_list list;
  78.     int code;
  79.     ref *pmark;
  80.  
  81.     check_read_type(*op, t_string);
  82.     iodev = gs_findiodevice(op->value.bytes, r_size(op));
  83.     if ( iodev == 0 )
  84.       return_error(e_undefinedfilename);
  85.     stack_param_list_write(&list, &o_stack, NULL);
  86. #define plist ((gs_param_list *)&list)
  87.     if ( (code = gs_getdevparams(iodev, plist)) < 0 )
  88.     {    ref_stack_pop(&o_stack, list.count * 2);
  89.         return code;
  90.     }
  91. #undef plist
  92.     pmark = ref_stack_index(&o_stack, list.count * 2);
  93.     make_mark(pmark);
  94.     return 0;
  95. }
  96.  
  97. /* <mark> <name> <value> ... <iodevice> .putdevparams */
  98. private int
  99. zputdevparams(os_ptr op)
  100. {    gx_io_device *iodev;
  101.     stack_param_list list;
  102.     int code;
  103.     check_read_type(*op, t_string);
  104.     iodev = gs_findiodevice(op->value.bytes, r_size(op));
  105.     if ( iodev == 0 )
  106.       return_error(e_undefinedfilename);
  107.     code = stack_param_list_read(&list, &o_stack, 1, NULL, false);
  108.     if ( code < 0 )
  109.       return code;
  110. #define plist ((gs_param_list *)&list)
  111.     code = param_check_password(plist, &SystemParamsPassword);
  112.     if ( code != 0 )
  113.       { iparam_list_release(&list);
  114.         return_error(code < 0 ? code : e_invalidaccess);
  115.       }
  116.     code = gs_putdevparams(iodev, plist);
  117.     iparam_list_release(&list);
  118.     if ( code < 0 )
  119.       return code;
  120. #undef plist
  121.     ref_stack_pop(&o_stack, list.count * 2 + 2);
  122.     return 0;
  123. }
  124.  
  125. /* ------ Initialization procedure ------ */
  126.  
  127. BEGIN_OP_DEFS(ziodev2_l2_op_defs) {
  128.         op_def_begin_level2(),
  129.     {"1.getdevparams", zgetdevparams},
  130.     {"2.putdevparams", zputdevparams},
  131. END_OP_DEFS(0) }
  132.